package likou;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        return;
    }

}


class Solution {
    public boolean isMatch(String s, String p) {
        char[] s1 = s.toCharArray();
        char[] p1 = p.toCharArray();

        if (p1.length > s1.length){
            return  false;
        }

        if(p1.length < s1.length){
            List<char[]> list = Arrays.asList(p1);
            boolean contains = list.contains('*');
            if (contains == false){
                return false;
            }
        }
        for (int i  = 0,j = 0;i < s1.length && j< p1.length;i++,j++){
               if (s1[i] == p1[j]|| p1[j] == '.'){
                    i++;j++;
               }else {
                   if (p1[j] == '*'){
                       while(p1[j-1] == s1[i]){
                           i++;
                       }

                       if (p1[j] != s1[i]){
                           j += 1;
                       }

                       if (p1[j-1] != s1[i]){
                           j += 1;
                       }
                   }
                   return false;
               }
        }
        return true;
    }
}
